<template>
  <el-dialog
    title="耗材使用情况（扣减记录）"
    destroy-on-close
    append-to-body
    :visible.sync="show"
    width="650px"
    :before-close="cancel">
    <el-table :height="calTableHeight() - 150" :data="tableData">
      <el-table-column show-overflow-tooltip :label="$t('耗材名称')" align="center" prop="cesName" />
      <el-table-column show-overflow-tooltip :label="$t('操作数量')" align="center" prop="num" />
      <el-table-column show-overflow-tooltip :label="$t('操作前数量')" align="center" prop="beforeNum" />
      <el-table-column show-overflow-tooltip :label="$t('	操作后数量')" align="center" prop="afterNum" />
    </el-table>

    <div slot="footer" class="dialog-footer">
      <el-button @click="cancel">
        <!-- 关闭 -->
        {{ $t('关闭') }}
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
import { getBatchSkuConsumableRecords } from '@/api/purchasingManage/batch'

export default {
  props: {
    /**
     * formData
     */
    formData: {
      type: Object,
      default: () => ({}),
    },

    /**
     * 控制显示隐藏
     */
    show: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      tableData: [],
    }
  },
  computed: {},
  watch: {
    show: function (newValue) {
      if (newValue) {
        this.getList()
      }
    },
  },
  methods: {
    getList() {
      this.tableData = []

      getBatchSkuConsumableRecords({ batchId: this.formData.id }).then((res) => {
        const { code, data, msg } = res
        if (code === 200) {
          this.tableData = data
        }
      })
    },
    cancel() {
      this.$emit('update:show', false)
    },
  },
}
</script>
<style scoped lang="scss"></style>
